#pragma once

#include "dfa_group.hpp"
#include <cstdint>
#include <unordered_map>

namespace dfa
{
	class DfaGroupManager
	{
	public:
	    DfaGroupManager() {};
	
	    DfaGroup* createNewGroup()
	    {
            DfaGroup* dfa_group = DfaGroup::createDfaGroup();
            _group_list.push_back(dfa_group);
            return dfa_group;
	    }

        DfaGroup* getContainingGroup(uint32_t dfa_state_num)
        {
            for (auto& e : _group_list) {
                if (groupContainingDfa(e, dfa_state_num)) {
                    return e;
                }
            }
            return nullptr;
        }

        auto getGroupCount()
        {
             return _group_list.size();
        }

        DfaGroup* getGroupAt(uint32_t index)
        {
            if (index < _group_list.size()) {
                return _group_list[index];
            }
            return nullptr;
        }

        auto size()
        {
            return _group_list.size();
        }

	    virtual ~DfaGroupManager() {};
	
	private:
        bool groupContainingDfa(DfaGroup* group, uint32_t dfa_state_num)
        {
            auto dfa_group = group->getGroup();
            for (auto& e : dfa_group) {
                if (e->getStateNum() == dfa_state_num) {
                    return true;
                }
            }
            return false;
        }

	    std::vector<DfaGroup*> _group_list;      
	};
	    
} /* namespace  */
